//
//  Tunnel.m
//  Communique
//
//  Created by Thomas on 27/08/2008.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "Tunnel.h"


@implementation Tunnel

@synthesize host=_host;
@synthesize nickname=_nickname;
@synthesize port1=_port1;
@synthesize port2=_port2;
@synthesize type=_type;

- (id) init
{
    if (self = [super init])
    {
        _host = @"localhost";
        _nickname = @"";
		_port1 = 0;
        _port2 = 0;
        _type = @"Local"; // local			
    }
    return self;
}

- (void) encodeWithCoder: (NSCoder *) coder { 
	[coder encodeObject: _nickname forKey:@"nickname"];
	[coder encodeObject: _host forKey:@"host"];
	[coder encodeInteger: _port1 forKey:@"port1"]; 
	[coder encodeInteger: _port2 forKey:@"port2"];
	[coder encodeObject: _type forKey:@"type"];  
} 

- (id) initWithCoder: (NSCoder *) coder { 
	if (self = [super init]) { 
		_host =			[coder decodeObjectForKey:@"host"]; 
		_port1 =		[coder decodeIntegerForKey:@"port1"]; 
		_port2 =		[coder decodeIntegerForKey:@"port2"]; 
		_nickname =		[coder decodeObjectForKey:@"nickname"]; 
		_type =			[coder decodeObjectForKey:@"type"]; 
	} 
	return self; 
}

- (NSString*) command {  
	
	NSString *type;
		
	if ([_type isEqualTo:@"Local"])
		type = @"-L";
	else
		type = @"-R";
	
	return [NSString stringWithFormat:@" %@ %@/%@/%@", type, [NSNumber numberWithInt:_port1], _host, [NSNumber numberWithInt:_port2]];
}


@end
